package bo;

import IBO.IEmployeInterne;
import boerrors.AdresseMinimumMultiplicityException;
import boerrors.CodePostalMinimumMultiplicityException;
import boerrors.EmployeExistantException;
import boerrors.EmployeInexistantException;
import boerrors.RoleMinimumMultiplicityException;
import boerrors.ZoneMinimumMultiplicityException;
import dao.AbstractFactory;
import dao.dto.EmployeDto;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;

public class EmployeInterne extends Employe implements IEmployeInterne, Cloneable{
 
	//*******************************************************************
	//Constructeurs
	//*******************************************************************    
        
        public EmployeInterne(EmployeDto employe) throws RemoteException {
                super(employe.getMatricule(), employe.getNom(), employe.getPrenom(), employe.getTelephone(),
                        employe.getEmail(), employe.getFonction(), employe.getPassword());
                Adresse adresse = new Adresse(employe.getAdresse());
                setAdresse(adresse);
                Role role = new Role(employe.getRole());
                enregistrerRole(role);
                UnicastRemoteObject.exportObject(this,0);
        }
    
        public EmployeInterne(  String nom, String prenom, Adresse adresse, 
                                String telephone, String email, Role role, 
                                String fonction, String password) throws RemoteException {
               super(nom, prenom, adresse, telephone, email, role, fonction, password);
                try {
                    AbstractFactory.getInstance().getEmployeDao().enregistrer(creerEmployeDto());
                    ListeEmployesInterne.getInstance().ajouterEmployeInterne(this);
                    UnicastRemoteObject.exportObject(this, 0);
                } catch (RoleMinimumMultiplicityException ex) {
                    Logger.getLogger(EmployeInterne.class.getName()).log(Level.SEVERE, null, ex);
                } catch (AdresseMinimumMultiplicityException ex) {
                    Logger.getLogger(EmployeInterne.class.getName()).log(Level.SEVERE, null, ex);
                } catch (CodePostalMinimumMultiplicityException ex) {
                    Logger.getLogger(EmployeInterne.class.getName()).log(Level.SEVERE, null, ex);
                } catch (ZoneMinimumMultiplicityException ex) {
                    Logger.getLogger(EmployeInterne.class.getName()).log(Level.SEVERE, null, ex);
                } catch (EmployeExistantException ex) {
                    Logger.getLogger(EmployeInterne.class.getName()).log(Level.SEVERE, null, ex);
                }
        }
        
        public EmployeInterne(  int matricule, String nom, String prenom, 
                                Adresse adresse, String telephone, String email, Role role,
                                String fonction, String password) throws RemoteException {
                super(matricule, nom, prenom, adresse, telephone, email, role, fonction, password);
                try {
                    AbstractFactory.getInstance().getEmployeDao().enregistrer(creerEmployeDto());
                    ListeEmployesInterne.getInstance().ajouterEmployeInterne(this);
                    UnicastRemoteObject.exportObject(this, 0);
                } catch (RoleMinimumMultiplicityException ex) {
                    Logger.getLogger(EmployeInterne.class.getName()).log(Level.SEVERE, null, ex);
                } catch (AdresseMinimumMultiplicityException ex) {
                    Logger.getLogger(EmployeInterne.class.getName()).log(Level.SEVERE, null, ex);
                } catch (CodePostalMinimumMultiplicityException ex) {
                    Logger.getLogger(EmployeInterne.class.getName()).log(Level.SEVERE, null, ex);
                } catch (ZoneMinimumMultiplicityException ex) {
                    Logger.getLogger(EmployeInterne.class.getName()).log(Level.SEVERE, null, ex);
                } catch (EmployeExistantException ex) {
                    Logger.getLogger(EmployeInterne.class.getName()).log(Level.SEVERE, null, ex);
                }
        }
 
        //*******************************************************************
	//Methodes static
	//*******************************************************************
        
        public synchronized static Vector<EmployeInterne> lister() throws RemoteException, EmployeInexistantException {
                Vector<EmployeDto> listeEmployeDto = AbstractFactory.getInstance().getEmployeDao().lister();
                Vector<EmployeInterne> listeEmploye = new Vector<EmployeInterne>();
                for (int i = 0 ; i < listeEmployeDto.size(); i++)
                    listeEmploye.add(new EmployeInterne(listeEmployeDto.get(i)));
                return listeEmploye;
        }
        
        public synchronized static void modifier(EmployeInterne employe) throws RemoteException {
                try {
                    AbstractFactory.getInstance().getEmployeDao().modifier(employe.creerEmployeDto());
                } catch (RoleMinimumMultiplicityException ex) {
                    Logger.getLogger(EmployeInterne.class.getName()).log(Level.SEVERE, null, ex);
                } catch (AdresseMinimumMultiplicityException ex) {
                    Logger.getLogger(EmployeInterne.class.getName()).log(Level.SEVERE, null, ex);
                } catch (CodePostalMinimumMultiplicityException ex) {
                    Logger.getLogger(EmployeInterne.class.getName()).log(Level.SEVERE, null, ex);
                } catch (ZoneMinimumMultiplicityException ex) {
                    Logger.getLogger(EmployeInterne.class.getName()).log(Level.SEVERE, null, ex);
                } catch (EmployeInexistantException ex) {
                    Logger.getLogger(EmployeInterne.class.getName()).log(Level.SEVERE, null, ex);
                }
        }

        //*******************************************************************
	//Method Clonable
	//*******************************************************************        
        
        @Override
        public Object clone(){
                // On récupère l'instance à renvoyer par l'appel de la 
                // méthode super.clone() (ici : Personne.clone())
                 EmployeInterne employe = (EmployeInterne) super.clone();
                // on renvoie le clone
                return employe;
        }
}